const paths = require('./paths');
const clear = require('rollup-plugin-clear');
const { nodeResolve } = require('@rollup/plugin-node-resolve');
const { babel } = require('@rollup/plugin-babel');
const commonjs = require('@rollup/plugin-commonjs');
const typescript = require('rollup-plugin-typescript2');
const postcss = require('rollup-plugin-postcss');
const babelConfig = require('./babel.config');
const autoprefixer = require('autoprefixer');
const url=require('@rollup/plugin-url');
const pkg=require("../package.json");
const prefix=pkg.cssPrefix||pkg.name;
module.exports={
  input: paths.input,
  output: {
    dir: paths.outputDir,
    format: 'cjs',
    banner: '// welcome to ww-building-blocks-tmp',
    footer: '// powered by ww',
    name: '[name].js',
    exports: 'named',
  },
  plugins: [
    clear({
      targets: [paths.outputDir],
    }),
    url({
      fileName:'[dirname][hash][extname]'
    }),
    postcss({
      extract: 'index.css',
      modules: {
        generateScopedName: `${prefix}_[local]`,
      },
      autoModules: false,
      plugins: [
          autoprefixer({
            overrideBrowserslist: [
              'last 10 Chrome versions',
              'last 5 Firefox versions',
              'Safari >= 6',
              'ie> 8',
            ],
          })
      ],
    }),
    typescript({
      tsconfigOverride: {
        exclude: [`src/demo/**/*`],
      },
    }),
    babel({
      exclude: 'node_modules/**',
      extensions: ['.ts', '.tsx', '.js', '.jsx'],
      babelHelpers: 'runtime',
      ...babelConfig,
    }),
    nodeResolve({
      resolveOnly: ['node_modules'], //定义为模块
    }),
    commonjs({
       include:["node_modules"]
    }),
  ],
};
